package cn.edu.neusoft.yuejian4.yuejian_4.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.Config.Server;
import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.ClubClass;

/**
 * Created by Lix on 2018/10/login_bg2.
 */

public class ClubClassAdapter  extends RecyclerView.Adapter<ClubClassAdapter.ViewHolder> {

    private List<ClubClass> mClubClass;
    private Context mContext;

    public ClubClassAdapter(Context mContext, List<ClubClass> mClubClass){
        this.mContext = mContext;
        this.mClubClass = mClubClass;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public ClubClassAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.club_class_cardview,parent,false);
        ClubClassAdapter.ViewHolder holder = new ClubClassAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ClubClassAdapter.ViewHolder holder, int position) {

        final ClubClass clubClass = mClubClass.get(position);
        holder.clubclassName.setText(clubClass.getClass_name());
        holder.clubclassprice.setText(Integer.toString(clubClass.getPrice()));
        Picasso.with(mContext)
                .load(Server.PIC_URL_J+clubClass.getPic())
                .placeholder(R.drawable.ic_default_img)
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .into(holder.clubclassImg);

    }

    @Override
    public int getItemCount() {
        return mClubClass.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView clubclassImg;
        TextView clubclassName;
        TextView clubclassprice;
        FrameLayout clubclass_container;

        public ViewHolder(View view){
            super(view);
            clubclassImg= (ImageView)view.findViewById(R.id.clubclass_img);
            clubclassName = (TextView)view.findViewById(R.id.clubclass_name);
            clubclassprice = (TextView)view.findViewById(R.id.clubclass_price);
            clubclass_container = (FrameLayout)view.findViewById(R.id.clubclass_container);
        }
    }
}
